Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support rewrite.inactiveRecipes #569

Closed
wants to merge 1 commit into from
Closed

Conversation

JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Jun 2, 2023

What's changed?

support rewrite.inactiveRecipes

What's your motivation?

when i use a recipe (it consist of many recipe), maybe i want disable some leaf-recipe.

Anything in particular you'd like reviewers to focus on?

please focus on is this idea is right?

Anyone you would like to review specifically?

anyone

Have you considered any alternatives or workarounds?

Recipe class add property enable. when enable is false this Recipe not work.

rewrite-maven-plugin set param rewrite.inactiveRecipes .

rewrite-maven-plugin find those recipes to recipe.setEnable(false)

is this idea better? but implement code difficult

Any additional context

none

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ auto-formatter on affected files
  • I've updated the documentation (if applicable)

@timtebeek timtebeek added the enhancement New feature or request label Jun 5, 2023
@timtebeek
Copy link
Contributor

timtebeek commented Jun 5, 2023

Hi @JoeCqupt ! Thank you for looking into this; it's indeed a frequent request to be able to exclude one or more recipes, which we have so far pushed back upon. The reason is it's typically possible to work around such issues by creating a separate rewrite.yml description file, which only contains the desired recipes.

It's more complicated than the current implementation to reliably implements exclusions, as recipes can also directly invoke each other, which is becoming quite common as well. I believe such direct invocations would not be picked up with the current implementation, and would not be trivial to implement.

There's also potential for issues when recipes assume preceding recipes have run before they make their own changes, which will be hard to reliably detect and prevent. In the past for instance we've had to request not to migrate just yet to JUnit Jupiter as part of the Spring Boot 2.4 migration. If we would allow exclusions, then we suddenly can't be certain anymore that users are on JUnit Jupiter in any of the Spring Boot 2.4+ recipes, which really complicates the logic for all recipes involved. There's more such examples where exclusions might trip up migrations in unexpected ways, which is why we've found it easier not to support exclusions rather than open it up for potential misuse, which we then have to counteract.

We do try to be conservative with the recipes we include with our common larger composite recipes, such that there should rarely be a need for exclusions, especially with the rewrite.yml workaround available as well. When issues do occur with included recipes, we prefer to fix those bugs quickly rather than allow for exclusions that might lead to harder to debug issues down the line.

So as much as we appreciate you contributing to the project, at this stage I'm uncertain whether this particular proposal is one we would be open to adopt. I'll raise it again internally, but wanted to give you this background such that you know it's both more complicated than expected, and has a potential for further issues that we hope to prevent.

Feel free to add your own perspective here as well; you likely have a couple of use cases that you might have hoped to use this feature for, and I hope we are able to work through those for you in some other way!

@timtebeek timtebeek mentioned this pull request Jun 5, 2023
@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Jun 6, 2023

ok. i get it.

@JoeCqupt JoeCqupt closed this Jun 6, 2023
@timtebeek
Copy link
Contributor

Yes sorry to see you've spent time on something we won't continue with for now. You're always welcome to contribute in some other way! You can also join our slack if there's anything you'd want to discuss up front before diving in. And like I said before: happy to work through any issues that prompted you to consider exclusions!

@tgeens
Copy link

tgeens commented Jul 18, 2023

Maybe there is a possibility to provide an optional .enabled configuration flag for recipes that are rather optional ?

For example: UpgradeSpringBoot_3_1 transitively pulls in org.openrewrite.java.spring.ImplicitWebAnnotationNames, removing explicitly named request-parameters from RestController signatures. If this goes against my projects' style guide, I might be better off not using OpenRewrite ?

@timtebeek
Copy link
Contributor

Hi @tgeens ; Sorry to hear you're unhappy with the inclusion of ImplicitWebAnnotationNames. For reference that comes in through our Spring Boot 2 best practices, which we run as part of our Migration to Spring Boot 2.0. That's indeed potentially a lot of yaml recipes to copy if you were to follow the above recommended approach.

It's not immediately clear to me which recipes you'd like to add a .enabled configuration option to; it sounds very much like a skip option by another name to me, which would suffer from the same drawbacks as outlined above.

Perhaps you'd be interested in following this PR, which aims to allow you to run individual minor Spring release migrations in isolation. That could provide you with an alternative here, as you likely already made the leap from 1.5 to 2.x+. Could that be a way forward for you?

@timtebeek
Copy link
Contributor

These days you can create your own custom recipe based off of an existing recipe most easily through the Moderne recipe builder. You can read more about the new recipe builder on the Moderne blog. We think this is the best way forward to allow for customization. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants